﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class UpdatePicCommandHander : IRequestHandler<UpdatePicCommand, ApiResult<object>>
    {
        public readonly IRepistory<Picture> _Picturerepistory;
        public readonly IMapper _mapper;
        public UpdatePicCommandHander(IRepistory<Picture> picturerepistory, IMapper mapper)
        {
            _Picturerepistory = picturerepistory;
            _mapper = mapper;
        }
       /// <summary>
       /// 图片修改
       /// </summary>
       /// <param name="request"></param>
       /// <param name="cancellationToken"></param>
       /// <returns></returns>
        public Task<ApiResult<object>> Handle(UpdatePicCommand request, CancellationToken cancellationToken)
        {
           ApiResult<object> apiResult = new ApiResult<object>();
            var result = _Picturerepistory.GetAll().FirstOrDefault(x => x.BatchId == request.BatchId);
            result.BatchId= request.BatchId;
            result.Pic = request.Pic;
            _Picturerepistory.Update(result);
           apiResult.Data = result;
           apiResult.Message = Renum.修改成功.ToString();
           apiResult.code =Renum.修改成功 ;
           return Task.FromResult(apiResult);
          
        }
    }
}
